package com.filldream.fastboot.base.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * OSS资源
 * </p>
 *
 * @author RickSun
 * @since 2020-11-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class OssResource implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "文件ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "类型 1-本地 2-阿里 3-腾讯")
    private Integer type;

    @ApiModelProperty(value = "文件前缀",example = "FillDream")
    private String filePrefix;

    @ApiModelProperty(value = "文件后缀",example = ".jpg")
    private String fileSuffix;

    @ApiModelProperty(value = "文件大小,字节",example = "1024")
    private Integer fileLength;

    @ApiModelProperty(value = "文件大小(可读)",example = "1.24MB")
    private String fileSize;

    @ApiModelProperty(value = "原始文件名称",example = "fillDream.jpg")
    private String originalName;

    @ApiModelProperty(value = "现名称",example = "FillDream.jpg")
    private String fileName;

    @ApiModelProperty(value = "地址前缀",example = "https://xxx.oss-cn-shanghai.aliyuncs.com")
    private String urlPrefix;

    @ApiModelProperty(value = "相对地址",example = "/fastboot/FillDream.jpg")
    private String relativePath;

    @ApiModelProperty(value = "绝对地址",example = "https://xxx.oss-cn-shanghai.aliyuncs.com/fastboot/FillDream.jpg")
    private String fileUrl;

    @ApiModelProperty(value = "文件MD5校验码")
    private String md5Str;

    public OssResource ok(String relativePath){
        this.relativePath = relativePath;
        this.fileUrl = this.urlPrefix + this.relativePath;
        if( urlPrefix.contains("aliyuncs") ){
            this.type = 2;
        }else if( urlPrefix.contains("/common/") ){
            this.type = 1;
        }else{
            this.type = 3;
        }
        return this;
    }


}
